//
//  CustomDetailTextTableViewCell.m
//  NBTripe
//
//  Created by Lee on 16/1/12.
//  Copyright © 2016年 Vicki. All rights reserved.
//

#import "CustomDetailTextTableViewCell.h"

@interface CustomDetailTextTableViewCell ()

@property (nonatomic, strong) UIImageView *lianjieimageview;

@property (nonatomic, strong) UILabel *lianjielabel;

@end

@implementation CustomDetailTextTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor colorWithRed:0.98 green:0.96 blue:0.88 alpha:1];
        CGRect rect = CGRectMake(10*XWIDTH, 40*XHIGHT, WIDTH-20*XWIDTH, 220*XHIGHT);
        self.picimageview = [[HJShapedImageView alloc] initWithFrame:rect];
        self.picimageview.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didPress)];
        [self.picimageview addGestureRecognizer:tap];
        self.daylabel = [[UILabel alloc] initWithFrame:CGRectZero];
        self.daylabel.backgroundColor = [UIColor colorWithRed:0.98 green:0.96 blue:0.88 alpha:1];
        
        [Convenience createCellLabel:self.daylabel LabelWithTextColor:[UIColor grayColor] TextColorWithFont:[UIFont boldSystemFontOfSize:15] FontWithNSTextAlignment:NSTextAlignmentLeft TextAlignmentWithNumberOfLines:0];
        self.lianjielabel = [[UILabel alloc] initWithFrame:CGRectZero];
        self.lianjielabel.backgroundColor = [UIColor whiteColor];        self.textlabel = [[UILabel alloc] initWithFrame:CGRectZero];
        [Convenience createCellLabel:self.textlabel LabelWithTextColor:[UIColor darkGrayColor] TextColorWithFont:[UIFont systemFontOfSize:14] FontWithNSTextAlignment:NSTextAlignmentLeft TextAlignmentWithNumberOfLines:0];
        self.timelabel = [[UILabel alloc] initWithFrame:CGRectZero];
        self.timelabel.backgroundColor = [UIColor whiteColor];
        [Convenience createCellLabel:self.timelabel LabelWithTextColor:[UIColor blackColor] TextColorWithFont:[UIFont systemFontOfSize:12] FontWithNSTextAlignment:NSTextAlignmentCenter TextAlignmentWithNumberOfLines:0];
      
        [self addSubview:self.daylabel];
        [self addSubview:self.picimageview];
        [self addSubview:self.lianjielabel];
        [self addSubview:self.textlabel];
        [self addSubview:self.timelabel];
    }
    return self;
}
- (void)layoutSubviews {
    [super layoutSubviews];
    self.daylabel.frame = CGRectMake(10*XWIDTH, 0, WIDTH, 50*XHIGHT);
      self.lianjielabel.frame =CGRectMake(WIDTH/2+50, 0, 5*XWIDTH, 45*XHIGHT);
    //text自适应高度
    CGRect rect = [self.textlabel.text boundingRectWithSize:CGSizeMake(WIDTH-20, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil];
    self.textlabel.frame = CGRectMake(10*XWIDTH, self.picimageview.bottom, WIDTH-20, rect.size.height);
    
    self.timelabel.frame = CGRectMake(0, self.textlabel.bottom+10, WIDTH, 40*XHIGHT);

}
- (void)setWaypointmodel:(CustomDaysWayPointsModel *)waypointmodel {
    if (_waypointmodel != waypointmodel) {
        _waypointmodel = waypointmodel;
    }
    [_picimageview sd_setImageWithURL:[NSURL URLWithString:_waypointmodel.photo] placeholderImage:[UIImage imageNamed:@"160.jpg"]];
    self.textlabel.text = waypointmodel.text;
    self.timelabel.text = [NSString stringWithFormat:@"⏲️ %@", waypointmodel.local_time] ;
}
- (void)didPress {
    self.block(_row);
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
